<?php
class CalendarController
	extends BaseController
{
	public function start()
	{
		$this->registry->template->arr_jsScriptUrls = $this->arr_appConf['js_files'];
		$this->registry->template->arr_cssSriptUrls = $this->arr_appConf['css_style_sheets'];
		
		$o_navi = new ClaycodeNaviMenu(
			$this->o_configuration->getApplicationsArray(),
			array(
				'pretty_urls'=> true,
				'is_sub_navi'=> false
			)
		);
		$this->registry->template->s_navi = $o_navi->getNaviHtml();
		$this->registry->template->show('Calendar.php');
	}
	
	public function getMonthEvents()
	{
		
		$arr_articles = $this->o_em->getRepository('Article')->getArticlesByDateRange($_GET['start'], $_GET['end']);
		$arr_output = array();
		foreach($arr_articles as $o_article){
			$s_time = date('Y-m-d H:i:s',strtotime($o_article->getCreateDate()->format('Y-m-d H:i:s')." +1 hour"));
			$arr_output[] = array(
				'id'=> EncryptionHandler::get()->doEncrypt($o_article->getId()),
				'title'=> $o_article->getArticleTitle(), 
				'start'=> $o_article->getCreateDate()->format('Y-m-d H:i:s'),
				'end'=>$s_time,
				'allDay'=> false
			);
		}
		fw_util_outputJson($arr_output);
		/*
		
		
		$year = date('Y');
		$month = date('m');
		$arr_output = array(
			array(
				'id' => 111,
				'title' => "Event1",
				'start' => "$year-$month-10"
			),
		
			array(
				'id' => 222,
				'title' => "Event2",
				'start' => "$year-$month-20",
				'end' => "$year-$month-22"
			),
			
			array(
				'id' => 333,
				'title' => "Event3",
				'start' => "$year-$month-12"
			),
			
			array(
				'id' => 444,
				'title' => "Event4",
				'start' => "$year-$month-25",
				'end' => "$year-$month-30"
			)
		);
		fw_util_outputJson($arr_output);
		*/
	}
}